﻿#if UNITY_EDITOR
using Sirenix.OdinInspector.Editor;
using Sirenix.Utilities;
using Sirenix.Utilities.Editor;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;

public class SkillUnitEditerManager
{
    private static string treeMenuName = "";
    private static string path = "";

    public static void InitMenu<T>(OdinMenuTree tree) where T : MyScriptableObject
    {
        var scriptableObjectTypes = AssemblyUtilities.GetTypes(AssemblyTypeFlags.CustomTypes)
                .Where(x => x.IsClass && !x.IsAbstract && x.InheritsFrom(typeof(T)));

        treeMenuName = TypeUtils.GetZHNameByT<T>();
        path = TypeUtils.GetNameByT<T>() + "/";

        List<T> list = new List<T>();
        


        tree.Add(treeMenuName, new EditerTotalItemList<T>());
        LoadMenuInfo<T>(tree);
    }


    private static void LoadMenuInfo<T>(OdinMenuTree tree) where T : MyScriptableObject
    {
        List<string> fileNames = EditerFilesManager.GetFiles(MyAssetsConfig.skillAssetsPath + path);
        for (int i = 0; i < fileNames.Count; i++)
        {
            T item = AssetDatabase.LoadAssetAtPath<T>(MyAssetsConfig.skillAssetsPath + path + fileNames[i]);
            string name = ((item.desc == null || item.desc == "") ? item.name : item.desc);
            OdinMenuItem odinMenuItem = new OdinMenuItem(tree, name, item);
            tree.AddMenuItemAtPath(treeMenuName, odinMenuItem);
        }
    }

    
}

#endif